//
//  HotViewController.m
//  Hxcsfw
//
//  Created by 企友软mac on 2017/10/26.
//  Copyright © 2017年 企友软mac. All rights reserved.
//

#import "HotViewController.h"
#import "HotViewCell.h"
#import "SGQRCodeScanningVC.h"
#import "WWebViewController.h"
#import "HotLbtModel.h"
#import "HotRdtjModel.h"
#import "HotSxbbModel.h"
#import "UIButton+WebCache.h"
#import "AnswerModel.h"
#import "SchoolListViewController.h"
#import "HotAskViewCell.h"
#import "HotRecomViewCell.h"
#import "SearchViewController.h"
#import "SchoolViewController.h"
#import "WTabBar.h"
#import "TakePhotoViewController.h"
#import "TaxInfoViewController.h"
#import "HotKcsdModel.h"
#import "UIImageView+WebCache.h"
#import "VideoDetailViewController.h"
#import "AnswerSortViewController.h"
#import "DiagramViewController.h"
#import "AudioPlayerManage.h"
#import "UIImageView+WebCache.h"
#import "HotRecomModel.h"

@interface HotViewController ()<UITableViewDataSource, UITableViewDelegate, HotViewCellDelegate, HotAskViewCellDelegate, UIAlertViewDelegate>
{
    //版本更新BOOL
    BOOL isUpdate;
    int j;
}
@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong)NSMutableArray *arrLbt;
@property (nonatomic, strong)NSMutableArray *arrRdtj;
@property (nonatomic, strong)NSMutableArray *arrSxbb;
@property (nonatomic, strong)NSMutableArray *arrKcsd;

@property (nonatomic, strong)NSMutableArray *arrAnswer;

@property (nonatomic, strong)NSMutableArray *arrRecom;

@end

@implementation HotViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _arrLbt = [NSMutableArray array];
    _arrRdtj = [NSMutableArray array];
    _arrSxbb = [NSMutableArray array];
    _arrKcsd = [NSMutableArray array];
    _arrAnswer = [NSMutableArray array];
    _arrRecom = [NSMutableArray array];

    [self.view addSubview:self.tableView];
    [self.tableView.superview insertSubview:[UIView new] atIndex:0];

    [self hotVcDataRequest];
    [self hotVcDataKcsdRequest];
    [self hotVcDataRequestStrNum:@"1" isRefrsh:YES];

    [self hotVcDJDZWDataRequest];
    [self notifyRequestListData];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(noWifiRefershingEnd) name:NOREFRESH object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notifyRequestListData) name:HOME_HOT_NOTIFY object:nil];

    //版本更新
    isUpdate = NO;
    [self getData];
}

- (void)noWifiRefershingEnd {
    [self.tableView.header endRefreshing];
    [self.tableView.footer endRefreshing];
    [WShareUtil sharedData].isShowWait = YES;

}

- (void)notifyRequestListData{
    self.tableView.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self hotVcDataRequest];
        [self hotVcDJDZWDataRequest];
        [self hotVcDataRequestStrNum:@"1" isRefrsh:YES];
        j = 1;
    }];

    self.tableView.footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        NSString *num = [NSString stringWithFormat:@"%d",++j];
        [self hotVcDataRequestStrNum:num isRefrsh:NO];
    }];
}

- (UITableView *)tableView {
    if (_tableView == nil) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, WSCREENH_WIDTH, WSCREENH_HEIGHT - 64 - 44 - 49 ) style:UITableViewStylePlain];
        self.tableView.estimatedRowHeight =0;
        self.tableView.estimatedSectionHeaderHeight =0;
        self.tableView.estimatedSectionFooterHeight =0;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;//去掉横线
    }
    return _tableView;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 2) {
        return self.arrRecom.count;
    }
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section == 0) {
        return 500;
    } else if (indexPath.section == 1) {
        return 480;
    } else {
        if (indexPath.row == 0) {
            return 125;
        }
        return 85;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HOTCELL"];

    if (indexPath.section == 0) {
        if (cell == nil) {
            HotViewCell *hotViewCell = [[[NSBundle mainBundle] loadNibNamed:@"HotViewCell" owner:self options:nil] lastObject];
            hotViewCell.arrayOfAds = _arrLbt;
            if (_arrRdtj != nil && _arrRdtj.count > 0) {
                [hotViewCell.btnRank sd_setImageWithURL:[NSURL URLWithString:[_arrRdtj[2] imgsrc]] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"hot_rank.png"]];
//                [hotViewCell.btnRank sd_setImageWithURL:[NSURL URLWithString:[_arrRdtj[2] imgsrc]] forState:UIControlStateNormal];
                [hotViewCell.btnWrite sd_setImageWithURL:[NSURL URLWithString:[_arrRdtj[1] imgsrc]] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"hot_statement.png"]];
//                [hotViewCell.btnWrite sd_setImageWithURL:[NSURL URLWithString:[_arrRdtj[1] imgsrc]] forState:UIControlStateNormal];
                [hotViewCell.btnReceipt sd_setImageWithURL:[NSURL URLWithString:[_arrRdtj[0] imgsrc]] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"hot_receipt.png"]];
//                [hotViewCell.btnReceipt sd_setImageWithURL:[NSURL URLWithString:[_arrRdtj[0] imgsrc]] forState:UIControlStateNormal];
            }

            if (_arrSxbb != nil && _arrSxbb.count > 0) {
                hotViewCell.lbReport.text = [_arrSxbb[0] strTitle];
                hotViewCell.lbPolicy.text = [_arrSxbb[1] strTitle];
                hotViewCell.lbNew.text = [_arrSxbb[2] strTitle];

                hotViewCell.lbReportTime.text = [_arrSxbb[0] fbsj];
                hotViewCell.lbPolicyTime.text = [_arrSxbb[1] fbsj];
                hotViewCell.lbNewTime.text = [_arrSxbb[2] fbsj];

                if ([[_arrSxbb[0] wzlx] isEqualToString:@"sx"]) {
                    [hotViewCell.imgReport setImage:[UIImage imageNamed:@"hot_message.png"]];
                } else {
                    [hotViewCell.imgReport setImage:[UIImage imageNamed:@"hot_play.png"]];
                }
                if ([[_arrSxbb[1] wzlx] isEqualToString:@"sx"]) {
                    [hotViewCell.imgPolicy setImage:[UIImage imageNamed:@"hot_message.png"]];
                } else {
                    [hotViewCell.imgPolicy setImage:[UIImage imageNamed:@"hot_play.png"]];
                }
                if ([[_arrSxbb[2] wzlx] isEqualToString:@"sx"]) {
                    [hotViewCell.imgNew setImage:[UIImage imageNamed:@"hot_message.png"]];
                } else {
                    [hotViewCell.imgNew setImage:[UIImage imageNamed:@"hot_play.png"]];
                }
            }

            hotViewCell.delegate = self;
            cell = hotViewCell;
        }
    }else if (indexPath.section == 1) {
        if (cell == nil) {
            HotAskViewCell *hotAskViewCell = [[[NSBundle mainBundle] loadNibNamed:@"HotAskViewCell" owner:self options:nil] lastObject];
            if (_arrAnswer != nil && _arrAnswer.count > 0) {
                hotAskViewCell.lbAnswerNew.text = [_arrAnswer[0] title];
                hotAskViewCell.lbAnswerPolicy.text = [_arrAnswer[1] title];
                hotAskViewCell.lbAnswerReport.text = [_arrAnswer[2] title];


                [hotAskViewCell.imgAnswerNew sd_setImageWithURL:[NSURL URLWithString:[_arrAnswer[0] imgsrc]] placeholderImage:nil];
                [hotAskViewCell.imgAnswerPolicy sd_setImageWithURL:[NSURL URLWithString:[_arrAnswer[1] imgsrc]] placeholderImage:nil];
                [hotAskViewCell.imgAnswerReport sd_setImageWithURL:[NSURL URLWithString:[_arrAnswer[2] imgsrc]] placeholderImage:nil];

                if ([WShareUtil strNilOrEmpty:[_arrAnswer[0] audiosrc]]) {
                    hotAskViewCell.btnAnswerNew.hidden = YES;
                }
                if ([WShareUtil strNilOrEmpty:[_arrAnswer[1] audiosrc]]) {
                    hotAskViewCell.btnAnswerPolicy.hidden = YES;
                }
                if ([WShareUtil strNilOrEmpty:[_arrAnswer[2] audiosrc]]) {
                    hotAskViewCell.btnAnswerReport.hidden = YES;
                }
            }

            if (_arrKcsd != nil && _arrKcsd.count > 0) {
                hotAskViewCell.lbKcsdL.text = [_arrKcsd[0] strTitle];
                hotAskViewCell.lbKcsdM.text = [_arrKcsd[1] strTitle];
                hotAskViewCell.lbKcsdR.text = [_arrKcsd[2] strTitle];

                [hotAskViewCell.imgKcsdLeft sd_setImageWithURL:[NSURL URLWithString:[_arrKcsd[0] imgsrc]] placeholderImage:nil];
                [hotAskViewCell.imgKcsdMiddle sd_setImageWithURL:[NSURL URLWithString:[_arrKcsd[1] imgsrc]] placeholderImage:nil];
                [hotAskViewCell.imgKcsdRight sd_setImageWithURL:[NSURL URLWithString:[_arrKcsd[2] imgsrc]] placeholderImage:nil];
            }
            hotAskViewCell.delegate = self;
            cell = hotAskViewCell;
        }
    } else {
        if (cell == nil) {
            HotRecomViewCell *hotRecomViewCell = [[[NSBundle mainBundle] loadNibNamed:@"HotRecomViewCell" owner:self options:nil] lastObject];

            if (indexPath.row == 0) {
                UILabel *lbRecom = [[UILabel alloc] initWithFrame:CGRectMake(15, 15, 150, 20)];
                lbRecom.font = [UIFont systemFontOfSize:17];
                lbRecom.text = @"热点推荐";
                [hotRecomViewCell addSubview:lbRecom];
            }
            if (_arrRecom && _arrRecom.count > 0) {
                hotRecomViewCell.lbTitle.text = [self.arrRecom[indexPath.row] strTitle];
                [hotRecomViewCell.imgCell sd_setImageWithURL:[NSURL URLWithString:[self.arrRecom[indexPath.row] imgsrc]] placeholderImage:[UIImage imageNamed:@"school_image.png"]];

            }
            cell = hotRecomViewCell;
        }

    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    if (indexPath.section == 2) {
        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"热点推荐";
        
        webVc.shareTitle = [self.arrRecom[indexPath.row] strTitle];//分享标题
        webVc.strID = [self.arrRecom[indexPath.row] strId];//分享ID
        webVc.strType = @"sx";//分享类型税信
        
        webVc.strUrl = [self.arrRecom[indexPath.row] link];
        [self.navigationController pushViewController:webVc animated:YES];
    }
}

- (void)delegatiCarClick:(NSInteger)index {

    WWebViewController *webVc = [[WWebViewController alloc] init];
    webVc.strTitle = @"热点推荐";
    webVc.strUrl = [_arrLbt[index] link];
    [self.navigationController pushViewController:webVc animated:YES];
}

- (void)delegatBtnClick:(UIButton *)button {
    if (button.tag == 2000) {
        TaxInfoViewController *taxInfoVc = [[TaxInfoViewController alloc] init];
        [self.navigationController pushViewController:taxInfoVc animated:YES];
    }else if (button.tag == 2001) {
        if (self.delegate && [self.delegate respondsToSelector:@selector(delegatChangeView:)]){
            [self.delegate delegatChangeView:3];
        }
    }else if (button.tag == 2002) {
        if (self.delegate && [self.delegate respondsToSelector:@selector(delegatChangeView:)]){
            [self.delegate delegatChangeView:4];
        }
    }else if (button.tag == 2004) {
        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"税信";
        
        webVc.shareTitle = [self.arrSxbb[0] strTitle];//分享标题
        webVc.strID = [self.arrSxbb[0] strId];//分享ID
        webVc.strType = @"sx";//分享类型税信
        
        webVc.strUrl = [_arrSxbb[0] link];
        [self.navigationController pushViewController:webVc animated:YES];
    }else if (button.tag == 2005) {
        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"税信";
        
        webVc.shareTitle = [self.arrSxbb[1] strTitle];//分享标题
        webVc.strID = [self.arrSxbb[1] strId];//分享ID
        webVc.strType = @"sx";//分享类型税信
        
        webVc.strUrl = [_arrSxbb[1] link];
        [self.navigationController pushViewController:webVc animated:YES];
    }else if (button.tag == 2006) {
        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"税信";
        
        webVc.shareTitle = [self.arrSxbb[2] strTitle];//分享标题
        webVc.strID = [self.arrSxbb[2] strId];//分享ID
        webVc.strType = @"sx";//分享类型税信
        
        webVc.strUrl = [_arrSxbb[2] link];
        [self.navigationController pushViewController:webVc animated:YES];
    }else if (button.tag == 3000) {
        WLog(@"问吧分类");
        AnswerSortViewController *asVC = [[AnswerSortViewController alloc]init];
        asVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:asVC animated:YES];
    }else if (button.tag == 3001) {
        DiagramViewController *diagramVc = [[DiagramViewController alloc]init];
        diagramVc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:diagramVc animated:YES];
        WLog(@"图解问吧");

    }else if (button.tag == 9000) {
        SearchViewController *searchVc = [[SearchViewController alloc] init];
        [self.navigationController pushViewController:searchVc animated:NO];
    }
}

- (void)delegatAskBtnClick:(UIButton *)button {

    AudioPlayerManage *playerManage = [AudioPlayerManage playerManage];
    playerManage.delegatePlayer = self;

    if (button.tag == 4000) {
        self.tabBarController.selectedIndex = 2;
        WTabBar *wtabBar = (WTabBar *)self.tabBarController.tabBar;
//        [wtabBar.plusBtn setBackgroundImage:[UIImage imageNamed:@"WB_XZ@2x.png"] forState:UIControlStateNormal];
        [wtabBar.plusBtn setImage:[UIImage imageNamed:@"WB_XZ@2x.png"] forState:UIControlStateNormal];
    }else if (button.tag == 4001) {
//        [self hotVcSBDataRequest:@"tech" level2:@"sb"];
        self.tabBarController.selectedIndex = 2;
        [WShareUtil sharedData].strLevel = @"sb";
        [WShareUtil sharedData].strLevel2 = @"tech";
        [[NSNotificationCenter defaultCenter] postNotificationName:@"dd" object:nil userInfo:@{@"strLevel":@"sb",@"strLevel2":@"tech"}];
        WTabBar *wtabBar = (WTabBar *)self.tabBarController.tabBar;
//        [wtabBar.plusBtn setBackgroundImage:[UIImage imageNamed:@"WB_XZ@2x.png"] forState:UIControlStateNormal];
        [wtabBar.plusBtn setImage:[UIImage imageNamed:@"WB_XZ@2x.png"] forState:UIControlStateNormal];
    }else if (button.tag == 4002) {
//        [self hotVcSBDataRequest:@"tech" level2:@"kp"];
        self.tabBarController.selectedIndex = 2;
        [WShareUtil sharedData].strLevel = @"kp";
        [WShareUtil sharedData].strLevel2 = @"tech";
        [[NSNotificationCenter defaultCenter] postNotificationName:@"dd" object:nil userInfo:@{@"strLevel":@"kp",@"strLevel2":@"tech"}];
        WTabBar *wtabBar = (WTabBar *)self.tabBarController.tabBar;
//        [wtabBar.plusBtn setBackgroundImage:[UIImage imageNamed:@"WB_XZ@2x.png"] forState:UIControlStateNormal];
        [wtabBar.plusBtn setImage:[UIImage imageNamed:@"WB_XZ@2x.png"] forState:UIControlStateNormal];
    }else if (button.tag == 4003) {
//        [self hotVcSBDataRequest:@"tax" level2:@""];
        self.tabBarController.selectedIndex = 2;
        [WShareUtil sharedData].strLevel = @"";
        [WShareUtil sharedData].strLevel2 = @"tax";
        [[NSNotificationCenter defaultCenter] postNotificationName:@"dd" object:nil userInfo:@{@"strLevel":@"",@"strLevel2":@"tax"}];
        WTabBar *wtabBar = (WTabBar *)self.tabBarController.tabBar;
//        [wtabBar.plusBtn setBackgroundImage:[UIImage imageNamed:@"WB_XZ@2x.png"] forState:UIControlStateNormal];
        [wtabBar.plusBtn setImage:[UIImage imageNamed:@"WB_XZ@2x.png"] forState:UIControlStateNormal];
    }else if (button.tag == 4004) {
//        [self hotVcSBDataRequest:@"note" level2:@""];
        self.tabBarController.selectedIndex = 2;
        [WShareUtil sharedData].strLevel = @"";
        [WShareUtil sharedData].strLevel2 = @"note";
        [[NSNotificationCenter defaultCenter] postNotificationName:@"dd" object:nil userInfo:@{@"strLevel":@"",@"strLevel2":@"note"}];
        WTabBar *wtabBar = (WTabBar *)self.tabBarController.tabBar;
//        [wtabBar.plusBtn setBackgroundImage:[UIImage imageNamed:@"WB_XZ@2x.png"] forState:UIControlStateNormal];
        [wtabBar.plusBtn setImage:[UIImage imageNamed:@"WB_XZ@2x.png"] forState:UIControlStateNormal];
    }else if (button.tag == 4005) {
        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"大家都在问";
        
        webVc.shareTitle = [self.arrAnswer[0] title];//分享标题
        webVc.strID = [self.arrAnswer[0] ID];//分享ID
        webVc.strType = @"wz";//分享类型文章
        
        webVc.strUrl = [_arrAnswer[0] link];
        [self.navigationController pushViewController:webVc animated:YES];
    }else if (button.tag == 4006) {
        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"大家都在问";
        
        webVc.shareTitle = [self.arrAnswer[1] title];//分享标题
        webVc.strID = [self.arrAnswer[1] ID];//分享ID
        webVc.strType = @"wz";//分享类型文章
        
        webVc.strUrl = [_arrAnswer[1] link];
        [self.navigationController pushViewController:webVc animated:YES];
    }else if (button.tag == 4007) {
        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"大家都在问";
        
        webVc.shareTitle = [self.arrAnswer[2] title];//分享标题
        webVc.strID = [self.arrAnswer[2] ID];//分享ID
        webVc.strType = @"wz";//分享类型文章
        
        webVc.strUrl = [_arrAnswer[2] link];
        [self.navigationController pushViewController:webVc animated:YES];
    }else if (button.tag == 5000) {
        SchoolViewController *schoolVc = [[SchoolViewController alloc] init];
        schoolVc.isMore = YES;
        [self.navigationController pushViewController:schoolVc animated:YES];
    }else if (button.tag == 5001) {
        VideoDetailViewController *videoDetailVc = [[VideoDetailViewController alloc]init];
        videoDetailVc.strId = [_arrKcsd[0] strId];
        [self.navigationController pushViewController:videoDetailVc animated:YES];
    }else if (button.tag == 5002) {
        VideoDetailViewController *videoDetailVc = [[VideoDetailViewController alloc]init];
        videoDetailVc.strId = [_arrKcsd[1] strId];
        [self.navigationController pushViewController:videoDetailVc animated:YES];
    }else if (button.tag == 5003) {
        VideoDetailViewController *videoDetailVc = [[VideoDetailViewController alloc]init];
        videoDetailVc.strId = [_arrKcsd[2] strId];
        [self.navigationController pushViewController:videoDetailVc animated:YES];
    }else if (button.tag == 10000) {

        button.selected = !button.selected;
        if (button.selected) {

            [button setImage:[UIImage imageNamed:@"listen_pause.png"] forState:UIControlStateNormal];

            playerManage.currentUrl = [self.arrAnswer[0] audiosrc];
            [playerManage audioPlayerPlay];

        }else {
            [button setImage:[UIImage imageNamed:@"hot_playVedio.png"] forState:UIControlStateNormal];
            [playerManage audioPlayerPause];
        }

    }else if (button.tag == 10001) {
        button.selected = !button.selected;
        if (button.selected) {

            [button setImage:[UIImage imageNamed:@"listen_pause.png"] forState:UIControlStateNormal];

            playerManage.currentUrl = [self.arrAnswer[1] audiosrc];
            [playerManage audioPlayerPlay];

        }else {
            [button setImage:[UIImage imageNamed:@"hot_playVedio.png"] forState:UIControlStateNormal];
            [playerManage audioPlayerPause];
        }
    }else if (button.tag == 10002) {
        button.selected = !button.selected;
        if (button.selected) {

            [button setImage:[UIImage imageNamed:@"listen_pause.png"] forState:UIControlStateNormal];

            playerManage.currentUrl = [self.arrAnswer[2] audiosrc];
            [playerManage audioPlayerPlay];

        }else {
            [button setImage:[UIImage imageNamed:@"hot_playVedio.png"] forState:UIControlStateNormal];
            [playerManage audioPlayerPause];
        }
    }
}

- (void)viewWillDisappear:(BOOL)animated {
    AudioPlayerManage *playerManage = [AudioPlayerManage playerManage];
    [playerManage audioPlayerDestroy];
}

- (void)delegatCollectionBtnClick:(NSInteger)tag {
    if (tag == 0) {
#if TARGET_IPHONE_SIMULATOR
        [WShareUtil showAlert:@"温馨提示" message:@"请用真机扫描"];
        WLog(@"run on simulator");
        return;
#define SIMULATOR_TEST
#else
        //相机权限
        AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
        if (authStatus ==AVAuthorizationStatusRestricted ||//此应用程序没有被授权访问的照片数据。可能是家长控制权限
            authStatus ==AVAuthorizationStatusDenied)  //用户已经明确否认了这一照片数据的应用程序访问
        {
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"无法调用您的相机，是否去设置里面开启" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
            alertView.tag = 600;
            [alertView show];
        } else {
            //不定义SIMULATOR_TEST这个宏
            SGQRCodeScanningVC *QRVc = [[SGQRCodeScanningVC alloc] init];
            [self.navigationController pushViewController:QRVc animated:YES];
        }
#endif

    }else if (tag == 1) {
        if ([WShareUtil sharedData].dicSession) {

            UIStoryboard *mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            TakePhotoViewController *takePhotoVc = [mainStory instantiateViewControllerWithIdentifier:@"TakePhotoViewController"];
            takePhotoVc.title = @"手机拍服务";
            [self.navigationController pushViewController:takePhotoVc animated:YES];
        }else {
            [SVProgressHUD showImage:nil status:@"请先登录"];
            [SVProgressHUD setOffsetFromCenter:UIOffsetMake(0, WSCREENH_HEIGHT *0.5 - 70)];
            [SVProgressHUD dismissWithDelay:1.];
            [SVProgressHUD setBackgroundColor:[UIColor colorWithRed:0.9 green:0.91 blue:0.93 alpha:1]];
        }
    }else if (tag == 2) {
        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"在线客服";
        webVc.strUrl = @"http://www.sobot.com/chat/pc/index.html?sysNum=79f43fe7ebd049898175758d0b00d986";
        [self.navigationController pushViewController:webVc animated:YES];
    }else if (tag == 3) {
        self.tabBarController.selectedIndex = 1;
    }else if (tag == 4) {
        self.tabBarController.selectedIndex = 1;
    }else if (tag == 5) {
        self.tabBarController.selectedIndex = 1;
    }
}

//首页请求
- (void)hotVcDataRequest {

    [WShareUtil sharedData].isShowWait = NO;

    // train
    NSDictionary *parametersDict = @{@"mode":@"native",@"service":@"init",@"content":@{@"screen":@"init"}};
    NSString *secret = [NSString stringWithFormat:@"%@",[WHttpTool convertToJsonData:parametersDict]];
    NSDictionary *paramsDic = @{@"params":[CommonFunc encryptWithText:secret]};


    [WHttpTool POST:[WShareUtil getServerURL:nil] parameters:@{@"params":[CommonFunc encryptWithText:secret]} success:^(id responseObject) {
        NSString *responseStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
        NSDictionary *JsonDic = [WHttpTool dictionaryWithJsonString:responseStr];
        NSString *messageStr = [JsonDic objectForKey:@"message"];
        NSString *successStr = [JsonDic objectForKey:@"success"];
        // 解密请求回的数据（字典）
        NSString *returnStr = [CommonFunc decryptWithText:messageStr];
        // json字符串转字典
        NSDictionary *returnDic = [WHttpTool dictionaryWithJsonString:returnStr];

        [WShareUtil sharedData].arrayOfAds = returnDic[@"lbt"];
        [self.arrLbt removeAllObjects];
        [self.arrSxbb removeAllObjects];

        for (NSDictionary *dic in returnDic[@"lbt"]) {
            HotLbtModel *lbtModel = [HotLbtModel mj_objectWithKeyValues:dic];
            [self.arrLbt addObject:lbtModel];
        }

        for (NSDictionary *dic in returnDic[@"sxbb"]) {
            HotSxbbModel *sxbbModel = [HotSxbbModel mj_objectWithKeyValues:dic];
            [self.arrSxbb addObject:sxbbModel];
        }

        [self noWifiRefershingEnd];
        [self.tableView reloadData];
    } failure:^(NSError *error) {
        [self noWifiRefershingEnd];
        WLog(@"失败");
    } showProgress:YES];
}

//课程速递请求
- (void)hotVcDataKcsdRequest {

    [WShareUtil sharedData].isShowWait = NO;
    // train
    NSDictionary *parametersDict;
    if ([WShareUtil sharedData].dicSession) {
        parametersDict = @{@"mode":@"native",@"service":@"init",@"content":@{@"username":[WShareUtil sharedData].dicSession[@"nsrsbh"],@"screen":@"train",@"apptype":@"ios"}};
    } else {
        parametersDict = @{@"mode":@"native",@"service":@"init",@"content":@{@"screen":@"train",@"apptype":@"ios"}};
    }

    NSString *secret = [NSString stringWithFormat:@"%@",[WHttpTool convertToJsonData:parametersDict]];
    NSDictionary *paramsDic = @{@"params":[CommonFunc encryptWithText:secret]};


    [WHttpTool POST:[WShareUtil getServerURL:nil] parameters:@{@"params":[CommonFunc encryptWithText:secret]} success:^(id responseObject) {
        NSString *responseStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
        NSDictionary *JsonDic = [WHttpTool dictionaryWithJsonString:responseStr];
        NSString *messageStr = [JsonDic objectForKey:@"message"];
        NSString *successStr = [JsonDic objectForKey:@"success"];
        // 解密请求回的数据（字典）
        NSString *returnStr = [CommonFunc decryptWithText:messageStr];
        // json字符串转字典
        NSDictionary *returnDic = [WHttpTool dictionaryWithJsonString:returnStr];

        [self.arrKcsd removeAllObjects];

        for (NSDictionary *dic in returnDic[@"kcsd"]) {
            HotKcsdModel *kcsdModel = [HotKcsdModel mj_objectWithKeyValues:dic];
            [self.arrKcsd addObject:kcsdModel];
        }
        [self noWifiRefershingEnd];
        [self.tableView reloadData];
    } failure:^(NSError *error) {
        [self noWifiRefershingEnd];
        WLog(@"失败");
    } showProgress:YES];
}

////申报请求
//- (void)hotVcSBDataRequest:(NSString *)level level2:(NSString *)level2 {
//
//    NSDictionary *parametersDict = @{@"mode":@"native",@"service":@"fwwb",@"content":@{@"revert":@"paginate",@"level":level,@"level2":level2,@"pagesize":@"3",@"pagenumber":@"1"}};
//
//    NSString *secret = [NSString stringWithFormat:@"%@",[WHttpTool convertToJsonData:parametersDict]];
//    NSDictionary *paramsDic = @{@"params":[CommonFunc encryptWithText:secret]};
//
//
//    [WHttpTool POST:[WShareUtil getServerURL:nil] parameters:@{@"params":[CommonFunc encryptWithText:secret]} success:^(id responseObject) {
//        NSString *responseStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
//        NSDictionary *JsonDic = [WHttpTool dictionaryWithJsonString:responseStr];
//        NSString *messageStr = [JsonDic objectForKey:@"message"];
//        NSString *successStr = [JsonDic objectForKey:@"success"];
//        // 解密请求回的数据（字典）
//        NSString *returnStr = [CommonFunc decryptWithText:messageStr];
//        // json字符串转字典
//        NSDictionary *returnDic = [WHttpTool dictionaryWithJsonString:returnStr];
//
//        [self.arrAnswer removeAllObjects];
//
//        if ([level isEqualToString:@"tech"] && [level2 isEqualToString:@"sb"]) {
//            for (NSDictionary *dic in returnDic[@"data"]) {
//                AnswerModel *answerMode = [AnswerModel mj_objectWithKeyValues:dic];
//                [self.arrAnswer addObject:answerMode];
//            }
//        }else if ([level isEqualToString:@"tech"] && [level2 isEqualToString:@"kp"]) {
//            for (NSDictionary *dic in returnDic[@"data"]) {
//                AnswerModel *answerMode = [AnswerModel mj_objectWithKeyValues:dic];
//                [self.arrAnswer addObject:answerMode];
//            }
//        }else if ([level isEqualToString:@"tax"]) {
//            for (NSDictionary *dic in returnDic[@"data"]) {
//                AnswerModel *answerMode = [AnswerModel mj_objectWithKeyValues:dic];
//                [self.arrAnswer addObject:answerMode];
//            }
//        }else {
//            for (NSDictionary *dic in returnDic[@"data"]) {
//                AnswerModel *answerMode = [AnswerModel mj_objectWithKeyValues:dic];
//                [self.arrAnswer addObject:answerMode];
//            }
//        }
//        [self noWifiRefershingEnd];
//        NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:1];
//        [self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
//
//    } failure:^(NSError *error) {
//        [self noWifiRefershingEnd];
//        WLog(@"失败");
//    } showProgress:YES];
//}

//大家都在问
- (void)hotVcDJDZWDataRequest {

    [WShareUtil sharedData].isShowWait = NO;

    NSDictionary *parametersDict = @{@"mode":@"native",@"service":@"init",@"content":@{@"screen":@"faq",@"pagesize":@"3",@"pagenumber":@"1"}};

    NSString *secret = [NSString stringWithFormat:@"%@",[WHttpTool convertToJsonData:parametersDict]];
    NSDictionary *paramsDic = @{@"params":[CommonFunc encryptWithText:secret]};


    [WHttpTool POST:[WShareUtil getServerURL:nil] parameters:@{@"params":[CommonFunc encryptWithText:secret]} success:^(id responseObject) {
        NSString *responseStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
        NSDictionary *JsonDic = [WHttpTool dictionaryWithJsonString:responseStr];
        NSString *messageStr = [JsonDic objectForKey:@"message"];
        NSString *successStr = [JsonDic objectForKey:@"success"];
        // 解密请求回的数据（字典）
        NSString *returnStr = [CommonFunc decryptWithText:messageStr];
        // json字符串转字典
        NSDictionary *returnDic = [WHttpTool dictionaryWithJsonString:returnStr];

        [self.arrAnswer removeAllObjects];

        for (NSDictionary *dic in returnDic[@"djdzw"]) {
            AnswerModel *answerMode = [AnswerModel mj_objectWithKeyValues:dic];
            [self.arrAnswer addObject:answerMode];
        }

        [self.tableView reloadData];
        [self noWifiRefershingEnd];
        NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:1];
        [self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];

    } failure:^(NSError *error) {
        [self noWifiRefershingEnd];
        WLog(@"失败");
    } showProgress:YES];
}

#pragma mark - 接口获取版本号
-(void)getData {
    
    NSDictionary *parametersDict = @{@"mode":@"native",@"service":@"preload",@"content":@{@"revert":@"version",@"device":@"1"}};
    NSString *secret = [NSString stringWithFormat:@"%@",[WHttpTool convertToJsonData:parametersDict]];
    NSDictionary *paramsDic = @{@"params":[CommonFunc encryptWithText:secret]};
    

    [WHttpTool POST:[WShareUtil getServerURL:nil] parameters:@{@"params":[CommonFunc encryptWithText:secret]} success:^(id responseObject) {
        NSString *responseStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
        NSDictionary *JsonDic = [WHttpTool dictionaryWithJsonString:responseStr];
        NSString *messageStr = [JsonDic objectForKey:@"message"];
        NSString *successStr = [JsonDic objectForKey:@"success"];
        // 解密请求回的数据（字典）
        NSString *returnStr = [CommonFunc decryptWithText:messageStr];
        // json字符串转字典
        NSDictionary *returnDic = [WHttpTool dictionaryWithJsonString:returnStr];

        if(![returnDic[@"resultCode"] isEqualToString:@"NO_VALIBLE_VERSION"]){
            WLog(@"errorInfo:当前版本为最新版本");
            UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"有新版本了，快去下载吧" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
            [av show];
            isUpdate = YES;
        }
        
        /*
         NSString *versionContent = [returnDic objectForKey:@"content"];//版本内容
         updateUrl = [returnDic objectForKey:@"app_path"];//下载地址
         [WShareUtil sharedData].appDownloadUrl = [returnDic objectForKey:@"app_path"];//下载地址添加到单例中
         [self update:[returnDic objectForKey:@"versionName"]];//后台(商店)版本号//解注
         //             [self update:@"2.0"];//注释
         
         WLog(@"版本内容-> %@",versionContent);
         WLog(@"下载地址-> %@",updateUrl);
         WLog(@"新版本号-> %@",[returnDic objectForKey:@"versionName"]);
         */
        
    } failure:^(NSError *error) {
        WLog(@"失败");
    } showProgress:YES];
}
#pragma mark - 版本更新
-(void)update:(NSString *)banben
{
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    CFShow((__bridge CFTypeRef)(infoDictionary));
    NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];// app本地版本号
    
    WLog(@"%f",[banben doubleValue]);// 后台返回版本（商店版本）
    WLog(@"%f",[app_Version doubleValue]);// app本地版本号
    
    if ([banben doubleValue]>[app_Version doubleValue] && !isUpdate) {
        UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"有新版本了，快去下载吧" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [av show];
        isUpdate = YES;
    }
}

// 对比版本号后，跳转商店更新版本
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{

    if (alertView.tag == 600) {
        if (buttonIndex == 1) {
            // 无权限 引导去开启
            NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
            if ([[UIApplication sharedApplication]canOpenURL:url]) {
                [[UIApplication sharedApplication]openURL:url];
            }
        }
    } else {

        if (buttonIndex == 1) {

            NSString  *urlStr = @"http://itunes.apple.com/app/id1153466604";//注释1250271269财税通--1153466604纪检委
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlStr]];//注释
    //        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:updateUrl]];//解注
        }
    }
}

- (void)hotVcDataRequestStrNum:(NSString *)pageNum isRefrsh:(BOOL)isRefrsh{

    [WShareUtil sharedData].isShowWait = NO;

    NSDictionary *parametersDict = @{@"mode":@"native",@"service":@"sxfw",@"content":@{@"revert":@"sxbbpage",@"pagesize":@"10",@"pagenumber":pageNum}};
    NSString *secret = [NSString stringWithFormat:@"%@",[WHttpTool convertToJsonData:parametersDict]];
    NSDictionary *paramsDic = @{@"params":[CommonFunc encryptWithText:secret]};


    [WHttpTool POST:[WShareUtil getServerURL:nil] parameters:@{@"params":[CommonFunc encryptWithText:secret]} success:^(id responseObject) {
        NSString *responseStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
        NSDictionary *JsonDic = [WHttpTool dictionaryWithJsonString:responseStr];
        NSString *messageStr = [JsonDic objectForKey:@"message"];
        NSString *successStr = [JsonDic objectForKey:@"success"];
        // 解密请求回的数据（字典）
        NSString *returnStr = [CommonFunc decryptWithText:messageStr];
        // json字符串转字典
        NSDictionary *returnDic = [WHttpTool dictionaryWithJsonString:returnStr];

        if (isRefrsh) {
            [self.arrRecom removeAllObjects];
        }
        for (NSDictionary *dic in returnDic[@"data"]) {
            HotRecomModel *hotRecomModel = [HotRecomModel mj_objectWithKeyValues:dic];
            [self.arrRecom addObject:hotRecomModel];
        }

        if (self.arrSxbb.count > 0) {
            for (int i = 0; i < 6; i++) {
                for (int j = 0; j < 3; j++) {
                    if ([[self.arrRecom[i] strTitle] isEqualToString:[self.arrSxbb[j] strTitle]]) {
                        [self.arrRecom removeObject:self.arrRecom[i]];
                        break;
                    }
                }
            }
        }

        [self.tableView reloadData];

        // --- 图片式提醒
        UIView *view = [self.tableView viewWithTag:10000];
        [view removeFromSuperview];
        HHNonePage *_nonePage = [[HHNonePage alloc]init];
        _nonePage = nil;
        if (self.arrRecom.count == 0) {
            _nonePage = [[HHNonePage alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
            _nonePage.tag = 10000;
            [self.tableView addSubview:_nonePage];
        }
        if (self.arrRecom.count < 10) {
            // 拿到当前的上拉刷新控件，变为没有更多数据的状态
            [self.tableView.footer endRefreshingWithNoMoreData];
        }

        [self noWifiRefershingEnd];

    } failure:^(NSError *error) {
        [self noWifiRefershingEnd];
        WLog(@"失败");
    } showProgress:YES];
}



@end
